package io.renren.modules.customer.controller;

import io.renren.modules.job.task.SmsReplyQueryTask;
import io.renren.thirdparty.sms.domain.QueryResultItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author sean
 * @since 2020-03-22
 *
 * 短信状态被动回调地址
 */
@RestController
@RequestMapping("ext/sms/callback")
public class SmsCallbackController {

    private static final Logger LOGGER = LoggerFactory.getLogger(SmsCallbackController.class);

    @Autowired
    private SmsReplyQueryTask smsReplyQueryTask;

    /**
     * 被动接受短信供应商的回调，获取消息的状态
     * @return 返回处理结果
     */
    @RequestMapping(value = "/notify", method = RequestMethod.POST)
    public String notification(@RequestBody(required = false) List<QueryResultItem> resultItemList) {
        LOGGER.debug("Got notification from vendor with item size {}", resultItemList == null ? 0 : resultItemList.size());
        this.smsReplyQueryTask.updateStatusOrMoData(resultItemList);
        return "OK";
    }
}
